package com.wenwei.utils;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.view.View;


import com.wenwei.parking.Constant;
import com.wenwei.parking.R;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

/**
 * Created by Administrator on 2016/5/19.
 */
public class ShareUtils {

    private static String filePath = "";
    private static String path = "/sdcard/myHead/";//sd路径
    private  static Bitmap shareBitmap;

    public static void showProduct(final Context context){
        shareBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon1);
        setPicToView(shareBitmap);

        ShareSDK.initSDK(context);

        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();
// 分享时Notification的图标和文字  2.5.9以后的版本不调用此方法
//    oks.setNotification(R.Rdrawable.ic_launcher, getString(R.string.app_name));
        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
        oks.setTitle("掌亭");
        oks.setText("智慧停车，向往更美好的生活");
        oks.setUrl("http://www.baidu.com");
        // titleUrl是标题的网络链接，仅在人人网和QQ空间使用
        oks.setTitleUrl("http://wwww.baidu.com");
        oks.setImagePath(filePath);//确保SDcard下面存在此张图片

        oks.show(context);
    }



    /**
     * 保存图片到sd卡
     */
    private static void setPicToView(Bitmap mBitmap) {
        String sdStatus = Environment.getExternalStorageState();
        if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
            return;
        }
        FileOutputStream b = null;
        File file = new File(path);
        file.mkdirs();// 创建文件夹
        String fileName = path + "share.jpg";//图片名字
        filePath = fileName;
        try {
            b = new FileOutputStream(fileName);
            mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把数据写入文件
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                //关闭流
                b.flush();
                b.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
